package com.zshan.clinic.cms.controller.clinic;


import com.zshan.clinic.admin.entity.dto.ClinicInfoDTO;
import com.zshan.clinic.admin.entity.vo.ClinicInfoVo;
import com.zshan.clinic.admin.service.clinic.ClinicEmpService;
import com.zshan.clinic.admin.service.clinic.ClinicInfoService;
import com.zshan.clinic.cms.common.core.controller.BaseController;
import com.zshan.clinic.cms.common.core.domain.AjaxResult;
import com.zshan.clinic.cms.common.core.domain.entity.SysUser;
import com.zshan.clinic.common.enums.ReqSourceEnum;
import com.zshan.clinic.common.util.page.PageInfo;
import com.zshan.clinic.database.model.ClinicInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 诊所信息
 */
@RestController
@RequestMapping("/clinic/info")
public class ClinicController extends BaseController {


    @Autowired
    private ClinicInfoService clinicService;

    @Autowired
    private ClinicEmpService clinicEmpService;

    /**
     * 查询诊所列表
     * @param clinicId 诊所ID
     * @param clinicName 诊所名
     * @param admin 管理员名
     * @param phone 管理员电话
     * @param license 营业执照号
     * @param isEnabled 是否启用 yesOrNoEnum 1是0否
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getClinicListByCondition")
    public AjaxResult getClinicListByCondition(@RequestParam(name = "clinicId",required = false) Long clinicId,
                                               @RequestParam(name = "clinicName",required = false) String clinicName,
                                               @RequestParam(name = "admin",required = false) String admin,
                                               @RequestParam(name = "phone",required = false) String phone,
                                               @RequestParam(name = "license",required = false) String license,
                                               @RequestParam(name = "isEnabled",required = false) String isEnabled,
                                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
        PageInfo<ClinicInfoVo> pageInfo = clinicService.getClinicListByCondition(clinicId,clinicName,admin,phone,license,isEnabled,pageNo,pageSize);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 添加诊所
     * @param clinicInfoDTO
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ClinicInfoDTO clinicInfoDTO) {
        SysUser sysUser = getUser();
        clinicInfoDTO.setCreateUserId(sysUser.getUserId());
        clinicInfoDTO.setCreateBy(sysUser.getUserName());
        clinicService.add(clinicInfoDTO);
        return AjaxResult.success();
    }

    /**
     * 修改诊所
     * @param clinicInfoDTO
     * @return
     */
    @PostMapping("/update")
    public AjaxResult update(@RequestBody ClinicInfoDTO clinicInfoDTO) {
        SysUser sysUser = getUser();
        clinicInfoDTO.setUpdateUserId(sysUser.getUserId());
        clinicInfoDTO.setUpdateBy(sysUser.getUserName());
        clinicService.update(clinicInfoDTO, ReqSourceEnum.ADMIN.getValue());
        return AjaxResult.success();
    }

    /**
     * 启用诊所
     * @param clinicInfo
     * @return
     */
    @PostMapping("/enable")
   public AjaxResult enable(@RequestBody ClinicInfo clinicInfo) {
        SysUser sysUser = getUser();
        clinicInfo.setUpdateUserId(sysUser.getUserId());
        clinicInfo.setUpdateBy(sysUser.getUserName());
        clinicService.enable(clinicInfo);
        return AjaxResult.success();
    }

    /**
     * 停用诊所
     * @param clinicInfo
     * @return
     */
    @PostMapping("/disable")
    public AjaxResult disable(@RequestBody ClinicInfo clinicInfo) {
        SysUser sysUser = getUser();
        clinicInfo.setUpdateUserId(sysUser.getUserId());
        clinicInfo.setUpdateBy(sysUser.getUserName());
        clinicService.disable(clinicInfo);
        return AjaxResult.success();
    }

}
